<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>3489： A simple rmq problem</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix"> A simple rmq problem</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix"> A simple rmq problem</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                 A simple rmq problem                </h1>
                <p>时间限制：40s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：600MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">因为是<font face="Times New Roman">OJ</font><font face="宋体">上的题，就简单点好了。给出一个长度为</font><font face="Times New Roman">n</font><font face="宋体">的序列，给出</font><font face="Times New Roman">M</font><font face="宋体">个询问：在</font><font face="Times New Roman">[l,r]</font><font face="宋体">之间找到一个在这个区间里只出现过一次的数，并且要求找的这个数尽可能大。如果找不到这样的数，则直接输出</font><font face="Times New Roman">0</font><font face="宋体">。我会采取一些措施强制在线。</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'"><o:p>&nbsp;</o:p></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<!--EndFragment--></p><hr/><h3>输入格式</h3><p><p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">第一行为两个整数<font face="Times New Roman">N,M</font><font face="宋体">。</font><font face="Times New Roman">M</font><font face="宋体">是询问数，</font><font face="Times New Roman">N</font><font face="宋体">是序列的长度（</font><font face="Times New Roman">N&lt;=100000</font><font face="宋体">，</font><font face="Times New Roman">M&lt;=200000)</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">第二行为<font face="Times New Roman">N</font><font face="宋体">个整数，描述这个序列</font><font face="Times New Roman">{ai}</font><font face="宋体">，其中所有</font><font face="Times New Roman">1&lt;=ai&lt;=N</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">再下面<font face="Times New Roman">M</font><font face="宋体">行，每行两个整数</font><font face="Times New Roman">x</font><font face="宋体">，</font><font face="Times New Roman">y</font><font face="宋体">，</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">询问区间<font face="Times New Roman">[l,r]</font><font face="宋体">由下列规则产生（</font><font face="Times New Roman">OIER</font><font face="宋体">都知道是怎样的吧</font><font face="Times New Roman">&gt;_&lt;)</font><font face="宋体">：</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">l=min(<font face="宋体">（</font><font face="Times New Roman">x+lastans)mod&nbsp;n+1,(y+lastans</font><font face="宋体">）</font><font face="Times New Roman">mod&nbsp;n+1);</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">r=max(<font face="宋体">（</font><font face="Times New Roman">x+lastans)mod&nbsp;n+1,(y+lastans</font><font face="宋体">）</font><font face="Times New Roman">mod&nbsp;n+1);</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">Lastans<font face="宋体">表示上一个询问的答案，一开始</font><font face="Times New Roman">lastans</font><font face="宋体">为</font><font face="Times New Roman">0</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p></p><hr/><h3>输出格式</h3><p><p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'">一共<font face="Times New Roman">M</font><font face="宋体">行，每行给出每个询问的答案。</font></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: medium"><span style="font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p></p><hr/><h3>样例输入</h3><pre>10 10
6 4 9 10 9 10 9 4 10 4 
3 8
10 1
3 4
9 4
8 1
7 8
2 9
1 1
7 3
9 9

</pre><hr/><h3>样例输出</h3><pre>4
10
10
0
0
10
0
4
0
4
</pre><hr/><h3>提示</h3><p><p><br />
注意出题人为了方便，input的第二行最后多了个空格。</p>
<p>2015.6.24新加数据一组，2016.7.9放至40S,600M,但未重测</p>
<p>&nbsp;</p></p><hr/><h3>题目来源</h3><p> by zhzqkkk</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=3489" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=3489" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>